import React, { useState, useRef } from 'react'

import "./App.css"
import {permits} from "./data"

export default function App() {
  const list = JSON.parse(JSON.stringify(permits))

  const menus = ()=>{
    const top = list.find(p=>p.parentId===0)
    generator(top, list)
  }

  const generator= (parent, list)=>{
    const children = list.filter(child=>child.parentId===parent.id)
    if(children && children.length>0){
      children.forEach(c => {
        generator(c, list)
      });
      parent.child = children
    }
  }

  return (
  <nav>
    {
      menus()
    }
  </nav> 
  )
}
